This program examines blocks that only partially intersect with community districts.

General information

The starting point for downloading most Census shapefiles is here. You can find more about the census redistricting files here.

It helps to know the FIPS (Federal Information Processing System) codes for Kansas (20) and Missouri (29).

The important counties for this program are

Cass County, MO (29037) Clay County, MO (29047) Jackson County, MO (29095) Johnson County, KS (20091) Leavenworth County, KS (20103) Platte County, MO (29165) Wyandotte County, KS (20209)

Load relevant files

library(sf)
## Linking to GEOS 3.9.1, GDAL 3.2.1, PROJ 7.2.1; sf_use_s2() is TRUE
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5     v purrr   0.3.4
## v tibble  3.1.6     v dplyr   1.0.8
## v tidyr   1.2.0     v stringr 1.4.0
## v readr   2.1.2     v forcats 0.5.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(magrittr)
## 
## Attaching package: 'magrittr'
## The following object is masked from 'package:purrr':
## 
##     set_names
## The following object is masked from 'package:tidyr':
## 
##     extract
path_name <- "../data/"
load(paste0(path_name, "bl", ".RData"))
glimpse(bl)
## Rows: 39,903
## Columns: 18
## $ statefp    <chr> "20", "20", "20", "20", "20", "20", "20", "20", "20", "20",~
## $ countyfp   <chr> "091", "091", "091", "091", "091", "091", "091", "091", "09~
## $ tract      <chr> "051801", "051400", "051500", "980003", "980003", "052505",~
## $ block      <chr> "2010", "3006", "2005", "1009", "1005", "2007", "1000", "20~
## $ GEOID20    <chr> "200910518012010", "200910514003006", "200910515002005", "2~
## $ NAME20     <chr> "Block 2010", "Block 3006", "Block 2005", "Block 1009", "Bl~
## $ MTFCC20    <chr> "G5040", "G5040", "G5040", "G5040", "G5040", "G5040", "G504~
## $ UR20       <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,~
## $ UACE20     <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,~
## $ UATYPE20   <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,~
## $ FUNCSTAT20 <chr> "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S", "S",~
## $ ALAND20    <dbl> 38533, 51754, 104623, 0, 95934, 199509, 30765, 354042, 7350~
## $ AWATER20   <dbl> 0, 0, 0, 73995, 0, 0, 0, 1582, 0, 0, 0, 0, 111, 0, 19008, 1~
## $ INTPTLAT20 <chr> "+38.9760924", "+38.9791667", "+38.9778033", "+38.9859944",~
## $ INTPTLON20 <chr> "-094.6412527", "-094.6370261", "-094.6291535", "-094.80067~
## $ label      <chr> "200910518012010", "200910514003006", "200910515002005", "2~
## $ geometry   <POLYGON [°]> POLYGON ((-94.64213 38.9774..., POLYGON ((-94.63966~
## $ block_area <dbl> 38500.823, 51711.677, 104537.047, 73933.762, 95854.528, 199~
load(paste0(path_name, "cd", ".RData"))
glimpse(cd)
## Rows: 59
## Columns: 10
## $ State      <chr> "MO", "MO", "MO", "MO", "MO", "MO", "MO", "MO", "MO", "MO",~
## $ STATE_FIPS <dbl> 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,~
## $ CD_ID      <dbl> 106, 108, 113, 102, 129, 116, 114, 101, 105, 103, 107, 109,~
## $ shid       <chr> "country:us/state:mo/place:kansas_city_city/community_distr~
## $ CD_NAME    <chr> "East Side", "Old Northeast", "Greater Downtown", "Blue Val~
## $ NAME       <chr> "East Side", "Old Northeast", "Greater Downtown", "Blue Val~
## $ Shape_Area <dbl> 281713946, 118237260, 181920873, 216842752, 412671383, 2642~
## $ Shape_Leng <dbl> 71542.21, 46770.45, 59596.40, 90646.31, 97165.89, 79759.94,~
## $ geometry   <POLYGON [°]> POLYGON ((-94.52337 39.0941..., POLYGON ((-94.50777~
## $ label      <chr> "East Side", "Old Northeast", "Greater Downtown", "Blue Val~
load(paste0(path_name, "bl-cd", ".RData"))
glimpse(bl_cd)
## Rows: 15,748
## Columns: 12
## $ statefp    <chr> "29", "29", "29", "29", "29", "29", "29", "29", "29", "29",~
## $ countyfp   <chr> "095", "095", "095", "095", "095", "095", "095", "095", "09~
## $ tract      <chr> "002300", "006300", "002200", "002200", "002200", "002200",~
## $ block      <chr> "2014", "2017", "3001", "3004", "3005", "3003", "3007", "10~
## $ block_area <dbl> 14983.197, 9597.627, 18151.722, 18380.541, 17691.230, 17458~
## $ POP100     <chr> "62", "0", "22", "26", "42", "49", "43", "0", "12", "20", "~
## $ HU100      <chr> "18", "0", "9", "18", "22", "22", "14", "0", "1", "10", "4"~
## $ cd_id      <dbl> 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106, 106,~
## $ cd_area    <dbl> 26153155, 26153155, 26153155, 26153155, 26153155, 26153155,~
## $ geometry   <GEOMETRY [°]> POLYGON ((-94.5324 39.0887,..., POLYGON ((-94.5612~
## $ in_area    <dbl> 14983.19694, 9597.62653, 18151.72239, 18380.54058, 17691.22~
## $ pct_in     <dbl> 100.0000000, 100.0000000, 100.0000000, 100.0000000, 100.000~

List blocks that are split between communities

bl_cd                                  %>%
  mutate(dev=abs(pct_in-50))           %>%
  arrange(dev)                          -> dev
dev                                    %>%
  print(n=20)
## Simple feature collection with 15748 features and 12 fields
## Geometry type: GEOMETRY
## Dimension:     XY
## Bounding box:  xmin: -94.90847 ymin: 38.8247 xmax: -94.38535 ymax: 39.35635
## Geodetic CRS:  NAD83
## First 20 features:
##         statefp countyfp  tract block block_area POP100 HU100 cd_id   cd_area
## 13731        20      209 044002  3008  38784.788      0     0   216   6664948
## 13731.1      20      209 044002  3008  38784.788      0     0   214  18315164
## 21619        29      047 020802  2021  53718.568      0     1   122  84211475
## 32452        29      095 013003  2035  14588.518      0     0   132  15605982
## 32452.1      29      095 013003  2035  14588.518      0     0   127  17728644
## 33457        29      095 016300  3006   8740.562      0     0   102  20130732
## 33457.1      29      095 016300  3006   8740.562      0     0   101  35453686
## 10843.2      20      209 040200  1004   1716.527      0     0   203   9497397
## 13509        20      209 043000  2016  12572.542      0     0   210   6804830
## 13509.1      20      209 043000  2016  12572.542      0     0   209   6026108
## 37499.1      29      165 030201  3030   2601.423     24     1   124 134952629
## 37499        29      165 030201  3030   2601.423     24     1   123  47453988
## 10843.1      20      209 040200  1004   1716.527      0     0   219   8068495
## 13517        20      209 980500  1033   8292.725      0     0   208  10499321
## 13517.1      20      209 980500  1033   8292.725      0     0   202   1611053
## 29503        29      095 012400  3004   2729.426     20     2   101  35453686
## 39142        29      165 030201  3032 306528.920    141    65   121  54659007
## 39142.1      29      165 030201  3032 306528.920    141    65   124 134952629
## 11734        20      209 043000  2019   4040.513      0     0   211  10110843
## 11734.1      20      209 043000  2019   4040.513      0     0   210   6804830
##             in_area   pct_in       dev                       geometry
## 13731    19470.0171 50.20014 0.2001381 POLYGON ((-94.74175 39.0779...
## 13731.1  19314.7708 49.79986 0.2001381 POLYGON ((-94.74511 39.0772...
## 21619    26475.4817 49.28553 0.7144685 POLYGON ((-94.45635 39.2447...
## 32452     7178.7392 49.20815 0.7918528 POLYGON ((-94.5281 38.93329...
## 32452.1   7409.7784 50.79185 0.7918529 POLYGON ((-94.52675 38.9332...
## 33457     4259.7065 48.73493 1.2650735 POLYGON ((-94.52097 39.0430...
## 33457.1   4480.8555 51.26507 1.2650735 POLYGON ((-94.52094 39.0428...
## 10843.2    881.2921 51.34157 1.3415739 POLYGON ((-94.65145 39.1529...
## 13509     6478.9517 51.53255 1.5325521 POLYGON ((-94.63498 39.0533...
## 13509.1   6093.5901 48.46745 1.5325521 POLYGON ((-94.64096 39.0492...
## 37499.1   1347.3418 51.79250 1.7924953 POLYGON ((-94.60092 39.2632...
## 37499     1254.0810 48.20750 1.7924953 POLYGON ((-94.60092 39.2625...
## 10843.1    827.4271 48.20355 1.7964528 POLYGON ((-94.65153 39.1529...
## 13517     4329.1369 52.20403 2.2040337 POLYGON ((-94.61271 39.0988...
## 13517.1   3963.5880 47.79597 2.2040338 POLYGON ((-94.61239 39.0980...
## 29503     1301.9518 47.70056 2.2994359 POLYGON ((-94.43716 39.0353...
## 39142   146019.5571 47.63647 2.3635299 MULTIPOLYGON (((-94.62606 3...
## 39142.1 160509.3970 52.36354 2.3635412 MULTIPOLYGON (((-94.62261 3...
## 11734     2117.4709 52.40599 2.4059852 POLYGON ((-94.64736 39.0511...
## 11734.1   1923.0426 47.59401 2.4059854 POLYGON ((-94.64631 39.0477...

Map split blocks

for (i in 1:500) {
  cd                                   %>%
    filter(CD_ID==dev$cd_id[i])         -> cd_i
  bl                                   %>%
    filter(statefp==dev$statefp[i])    %>%
    filter(countyfp==dev$countyfp[i])  %>%
    filter(tract==dev$tract[i])        %>%
    filter(block==dev$block[i])         -> bl_i
  ti <- paste0(
    cd_i$CD_NAME, ", ",
    bl_i$NAME20, ", ",
    round(dev$pct_in[i]), "%")
  cd_i                                 %>%
    ggplot(aes())                       +
      geom_sf(
        fill="white", 
        color="darkgreen")              +
      ggtitle(ti)                       +
      geom_sf(
        data=bl_i,
        aes(), 
        fill=NA,
        color="darkred")                -> map_i
  plot(map_i)
}